#ifndef ENGINE_H
#define ENGINE_H

#include <QString>
#include <QPixmap>
#include "definitions.h"
#include "statistics.h"

class Engine
{
public:
    static bool GameRunning;
    static Statistics GameStatistics;

    static Minion *FirstMinion;
    static Bullet *FirstBullet;
    static unsigned int TicksPerSecond;

    static Map *CurrentMap;

public:
    static QPixmap *LoadPicture(const QString &Filename);

    static void LoadMap(const QString &Filename);

    static void SpawnBullet(int Power, double X, double Y, double DestinationX, double DestinationY,
                            Minion *Target, double Speed, void *Picture, BulletFlags Flags, int Range);

    static Bullet *RemoveBullet(Bullet *BulletToRemove);

    static Minion *SpawnMinion(const QString &Filename, int Team,
                               double X, double Y, double Orientation, QString PlayerName = "");

    static Minion *RemoveMinion(Minion *MinionToRemove);

    static void EndGame();

    static void Tick();

    static bool CheckCollision(Minion *MovedMinion, double X, double Y, bool IgnoreDeadFlag = false);

    static bool IsVisible(Minion *CheckedMinion, int team);

    /*
     * Adjusts X and Y according to defined destination point, orientation and movement speed
     */
    static void Move(double &X, double &Y, double DestinationX, double DestinationY, double Orientation, double Speed);
    static void Move(Minion *MovedMinion, double DestinationX, double DestinationY, double Orientation);

    static bool Rotate(double &Orientation, double DestinationOrientation,
                       double RotationSpeed);

    /*
     * Returns 1 if minion should rotate clockwise to change from Current to Destination orientation
     * Returns -1 if minion should rotate anti-clockwise
     */
    static int GetRotationDirection(double Current, double Destination);

    /*
     * Returns orientation (0.0 - 1.0) which should be assigned to face Destination point from origin point
     */
    static double GetDestinationOrientation(double X, double Y, double DestinationX, double DestinationY);

    static void GetRespawnPoint(int Team, double &X, double &Y, int Point = -1);

    static Minion *FindNearestEnemy(Minion *OriginatorMinion, double &Distance);
    static Minion *FindNearestMinion(int X, int Y);

    static double GetDistance(double X1, double Y1, double X2, double Y2);
    static double GetDistance(Minion *FirstMinion, Minion *SecondMinion);
};

#endif // ENGINE_H
